package com.tlgen.modules.vocation.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tlgen.modules.common.domain.J_Area;
import com.tlgen.modules.system.domain.Menu;
import com.tlgen.modules.system.domain.User;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;

@Entity
@Data
@Table(name="family")
public class Family implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = Update.class)
    private Long id;

    @NotBlank
    private String countygroup;

    @NotBlank
    private String attr;

    private String address;

    @NotBlank
    @Column(unique = true)
    private String record;

    @NotBlank
    private String familyid;

    @NotBlank
    private String num;

    @NotBlank
    private String count;

    @Column(name = "createtime")
    @CreationTimestamp
    private Timestamp createtime;

    @OneToOne
    @JoinColumn(name = "j_areaid")
    private J_Area j_area;

    /**
     * 家庭户主所拥有的成员
     */
    @ManyToMany
    @JoinTable(name = "families_homes", joinColumns = {@JoinColumn(name = "family_id",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "home_id",referencedColumnName = "id")})
    private Set<Home> homes;

    public @interface Update {}

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Family family = (Family) o;
        return id.equals(family.id) &&
                record.equals(family.record);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, record);
    }
}
